<?php 
class Application_Model_QualityProblemContent extends Application_Model_DomainObject {
    
    protected $_id;
    /**
     * 问题ID
     */
    protected $_problemId;
    /**
     * 问题内容
     */
    protected $_content;
    /**
     * 创建时间
     */
    protected $_dateCreated;
    /**
     * 添加人
     */
    protected $_operator;
    /**
     * 状态
     */
    protected $_status;
    /**
     * 待处理
     */
    const Status_Default = 0;
    /**
     * 已处理
     */
    const Status_Complated = 1;
    /**
     * 绑定状态
     */
    const Status_Bind = 10;
    
    public function getStatusName()
    {
        switch ($this->_status) {
            case self::Status_Default:
                return "待处理";
                break;
            case self::Status_Complated:
                return "已处理";
                break;
            case self::Status_Bind:
                return "已绑定";
                break;
            default:
                return "待处理";
                break;
        }
    }

    public static function addQualityProblemContent($problemId,$content,$dateCreated,$operator,$status = self::Status_Default)
    {
        $qualityProblemContentItem = new Application_Model_QualityProblemContent();
        $qualityProblemContentItem->problemId = $problemId;
        $qualityProblemContentItem->content = $content;
        $qualityProblemContentItem->dateCreated = $dateCreated;
        $qualityProblemContentItem->operator = $operator;
        $qualityProblemContentItem->Status = $status;
        $qualityProblemContentItem->save();
        return $qualityProblemContentItem->Id;
    }
    
    public static function byProblemId($problemId)
    {
        return self::getDao()->queryAll(array("problemId = "=>$problemId));
    }
    
    public function getImgs()
    {
        $imgItem = Application_Model_QualityProblemImg::byContentId($this->_id); 
        return  $imgItem;
    }
    
    public function getImg()
    {
        $imgItem = Application_Model_QualityProblemImg::byContentId($this->_id);   
        if(!$imgItem){
            return false;
        }
        $imgArr = array();
        foreach ($imgItem as $imgVal) {
            $imgArr[$imgVal->Id]["imgUrl"] = !is_int(strpos('big',$imgVal->ImgUrl))?('/big'.$imgVal->ImgUrl):($imgVal->ImgUrl);
            $imgArr[$imgVal->Id]["img"] = $imgVal->ImgUrl;
        }
        return $imgArr;
    }
    
    public static function getNum($problemId,$status)
    {
        $where = array();
        $and = "";
        if($problemId != ""){
            $where[" problemId = "] = $problemId;
            $and = " and ";
        }
        if($status != ""){
            $where[$and." status = "] = $status;
            $and = " and ";
        }
        return self::getDao()->count($where);
    }
    
    public function getQualityProblem()
    {
        return Application_Model_QualityProblem::load($this->_problemId);
    }
    
    public function getDelTrack()
    {
        $problemItem = Application_Model_QualityProblem::load($this->_problemId);
        $trackItem = Application_Model_Tracking::getAllByObjectTypeIdOperateType($problemItem->objectType, $this->_id, Application_Model_Tracking::Type_Quality);
        if(!$trackItem){
            return true;
        }
        foreach ($trackItem as $trackVal) {
            $trackVal->delete();
        }
        return true;
    }
}